<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="提现金额" prop="amount">
      <el-input v-model="dataForm.amount" placeholder="提现金额"></el-input>
    </el-form-item>
    <el-form-item label="提现状态" prop="status">
   <!--    <el-input v-model="dataForm.status" placeholder="提现状态"></el-input> -->
                <el-switch
            v-model="dataForm.status"
            :active-value="1"
            :inactive-value="0"
            active-color="#13ce66"
            inactive-color="#ff4949"
          >
          </el-switch> 
    </el-form-item>
    <el-form-item label="提现时间" prop="time">
 <!--      <el-input v-model="dataForm.time" placeholder="提现时间"></el-input> -->
         <el-tag >{{dataForm.time}}</el-tag>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          uuid: 0,
          userId: '',
          amount: '',
          status: '',
          deleted: '',
          time: ''
        },
        dataRule: {
          userId: [
            { required: true, message: '用户提现id不能为空', trigger: 'blur' }
          ],
          amount: [
            { required: true, message: '提现金额不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '提现状态不能为空', trigger: 'blur' }
          ],
          deleted: [
            { required: true, message: '逻辑删除不能为空', trigger: 'blur' }
          ],
          time: [
            { required: true, message: '提现时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.uuid = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.uuid) {
            this.$http({
              url: this.$http.adornUrl(`/help/withdraw/info/${this.dataForm.uuid}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userId = data.withdraw.userId
                this.dataForm.amount = data.withdraw.amount
                this.dataForm.status = data.withdraw.status
                this.dataForm.deleted = data.withdraw.deleted
                this.dataForm.time = data.withdraw.time
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/help/withdraw/${!this.dataForm.uuid ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'uuid': this.dataForm.uuid || undefined,
                'userId': this.dataForm.userId,
                'amount': this.dataForm.amount,
                'status': this.dataForm.status,
                'deleted': this.dataForm.deleted,
                'time': this.dataForm.time
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
